<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>添加厂商</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <div class="layui-form layuimini-form">
            <div class="layui-form-item">
                <label class="layui-form-label required">厂商名</label>
                <div class="layui-input-block">
                    <input type="text" name="CusName" lay-verify="required" lay-reqtext="厂商名不能为空" placeholder="请输入厂商名"
                           class="layui-input">
                    <tip>添加重复厂商名会失败</tip>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label required">厂商备注</label>
                <div class="layui-input-block">
                    <textarea name="CusRemark" id="CusRemark" class="layui-textarea" placeholder="厂商备注"></textarea>
                    <tip>厂商相关信息,如主页、备案号等</tip>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="cus_add">确认添加</button>
                </div>
            </div>
        </div>

    </div>
</div>
<script src="/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var $ = layui.jquery,
            form = layui.form;

        //监听提交
        form.on('submit(cus_add)', function(data) {
            $.ajax({
                url: "/api/scan/manager",
                data: JSON.stringify(data.field),
                contentType: 'application/json;charset=UTF-8',
                dataType: 'json',
                type: 'put',
                success: function(result) {
                    if (result.code == 200) {
                        var index = layer.alert("添加厂商成功", {
                            title: '提示',
                            icon: 1
                        }, function() {
                            parent.layui.table.reload("currentTable_customer");
                            layer.close(index);
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        })
                    } else {
                        layer.alert(result.msg, {
                            title: '提示',
                            icon: 2
                        })
                    }
                },
                error: function (e) {
                    layer.alert(JSON.stringify(e), {title: '提示', icon: 2})
                }
            })
            return false;
        });
    });
</script>

</body>
</html>
